<template>
  <li class="setting-list__item">
    <div class="setting"
         :style="{backgroundColor:setting.info.color}"
    >

      <van-popover v-model="showPopover" placement="top-start" trigger="click">
        <div class="setting-intro" style="white-space: pre-line;">
          {{ setting.info.intro }}
        </div>
        <template #reference>
          <div class="setting-icon">
            <i class="iconfont" :class="setting.info.icon||'icon-shezhi-moren'"></i>
          </div>
        </template>
      </van-popover>
    </div>
    <div class="setting-data">
      <div class="setting-name">{{ setting.info.name }}</div>

      <input ref="switch" type="checkbox"
             :style="{backgroundColor:setting.value?setting.info.color:'',
             borderColor:setting.info.color,}"
             v-model:value="setting.value"
             class="form-switch setting-switch">
    </div>
  </li>
</template>

<script>
export default {
  name: "SettingCell",
  props: {
    setting: {
      type: Object
    },
  },
  data() {
    return {
      showPopover: false,
    }
  },
  methods: {},
  mounted() {
    this.$refs.switch.style.setProperty("--bcColor", this.setting.info.color);
  }
}
</script>

<style lang="less">

.setting-intro {
  font-size: 10px;
  border-radius: 20px;
  width: 200px;
  padding: 10px;
  background-color: rgba(255, 255, 255, 0.8);
  opacity: 0.8;
}

.setting-list__item {
  padding: 4px;
  background: var(--background-color);
  box-shadow: var(--box-shadow);

  border-radius: 15px;
  transition: 0.3s;

  .setting {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px;
    color: white;
    background: rgb(69, 72, 86);
    border-radius: 15px;

    .setting-icon {
      display: flex;
      justify-content: center;
      align-items: center;
      width: 40px;
      height: 40px;
      background: rgba(255, 255, 255, 0.2);
      border-radius: 10px;

      .iconfont {
        fill: currentcolor;
        width: 18px;
        height: 18px;
      }
    }
  }

  .setting-data {
    display: flex;
    justify-content: space-between;
    padding: 20px 16px 18px 16px;


    .setting-name {
      margin-right: 20px;
      white-space: nowrap;
      font-size: 15px;
    }

    .form-switch {
      position: relative;
      width: 40px;
      height: 22px;
      border: 1px solid #2a93ea;
      border-radius: 12px;
      cursor: pointer;
      transition: .3s;
    }

    .form-switch:checked::before {
      background: var(--switch-check-color);
      transform: translateX(18px);
    }

    .form-switch::before {
      position: absolute;
      content: "";
      top: 1px;
      left: 1px;
      width: 18px;
      height: 18px;
      background: var(--bcColor);
      border-radius: 50%;
      transition: .3s;
    }

    input {
      outline: 0;
      -webkit-appearance: none;
      -moz-appearance: none;
      appearance: none;
    }
  }
}

.van-popover__wrapper {
  cursor: pointer;
}
</style>